-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: module imports should not use type index as their function identifier #411
Conversation
@@ -0,0 +1,5 @@ | |||
(module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this simple test, which adds a couple of type definitions, was enough to repro the issues from #406
@@ -419,6 +417,8 @@ export function parse(tokensList: Array<Object>, source: string): Program { | |||
const fnParams = []; | |||
const fnResult = []; | |||
|
|||
let fnName = t.identifier(getUniqueName("func")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change was not necessarily needed to make tests pass, but this does mean we have the same generated names when parsing wat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following https://github.com/xtuc/webassemblyjs/pull/411/files#r202406723 we could add our own func increment, or maybe we already have this information?
The "AST synchronization" test suite in |
@@ -432,7 +432,7 @@ export function decode(ab: ArrayBuffer, opts: DecoderOpts): Program { | |||
throw new CompileError(`function signature not found (${typeindex})`); | |||
} | |||
|
|||
const id = t.numberLiteralFromRaw(typeindex); | |||
const id = getUniqueName("func"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should try to eliminate the unique name generator (because statefull), and rather use the typeindex
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should try to eliminate the unique name generator (because statefull)
I agree, that maybe the type name generator should be removed. I'm not sure what it's used for!
and rather use the typeindex here
No ... that's the bug that this PR is fixing. Module imports are functions which are referenced by index, i.e. if you have the following:
(type (func (result i32)))
(type (func (param i32) (result i32)))
(import "a" "c" (func $foo (type 1)))
(func $bar)
The function foo
has index 0
, and bar
has index 1. The index does not relate to the type reference.
OK - I'll explore further and see what I've broken! |
@xtuc ok, I've had a look at the test and understand what it is doing now. I've fixed the test by making the following changes:
|
The tests are currently failing, but looks like a CI issue rather than a unit test failure! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updates!
kicked Travis and the build works now :-) |
fixes #406
@xtuc there is a wasm-edit test failing as a result of this change, wondering if you have any pointers?